﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using QuantumWorkspace.SessionManager.QuantumUserRegistrationService;
using QuantumWorkspaces.DomainEntities;
using Raven.Client;
using Raven.Client.Document;

namespace QuantumWorkspace.SessionManager
{
    public class StaticAuthenticationDAL
    {

        private static StaticAuthenticationDAL _Instance;

        private QuantumUserRegistrationService.UserRegistrationServiceClient _registrationServiceClient;



        public static StaticAuthenticationDAL Instance
        {
            get
            {
                if (_Instance == null)
                {
                    _Instance = new StaticAuthenticationDAL();

                }
                return _Instance;
            }
        }

        private StaticAuthenticationDAL()
        {
            try
            {
                _registrationServiceClient = new UserRegistrationServiceClient();
            }
            catch (Exception ex)
            {
                var strMessage = ex.Message;
            }
        }




        public bool SendUserPasswordRequest(string strUserName)
        {
            return _registrationServiceClient.SendUserPasswordConfirmationMail(strUserName);
        }

        public bool IsEmailAlreadyRegistered(string strEmail)
        {
            return _registrationServiceClient.IsEmailAlreadyRegistered(strEmail);
        }


        public bool RegisterUser(string strUser, string strPassword, string strEmail)
        {

            bool result = _registrationServiceClient.RegisterUser(strUser, strPassword, strEmail);
            if (result)
                QuantumUserSession.IsLogged = true;
            return result;

        }

        /// <summary>
        /// Check if the password provided for the user is correct or not
        /// </summary>
        /// <param name="strUser"></param>
        /// <param name="strPassword"></param>
        /// <returns></returns>
        public bool WrongPasswordForUser(string strUser, string strPassword)
        {
            return _registrationServiceClient.WrongPasswordForUser(strUser, strPassword);
        }
    

        public bool LogIn(string strUser, string strPassword)
        {
            // bool result = true;

            bool result = _registrationServiceClient.LogIn(strUser, strPassword);
            if (result)
                QuantumUserSession.IsLogged = true;
            return result;
        }

        public bool LogOff()
        {
            if (!QuantumUserSession.IsLogged)
                return false;
            QuantumUserSession.IsLogged = false;
            QuantumUserSession.LogoffDate = DateTime.Now;
            return true;
        }

    }

   
}
